package pl.nazaweb.samplesandtutorials;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class Main extends Activity {

	Button shopProviderButton;
	Button textViewExampleButton;
	Button butonExamplesButton;
	Button shopListButton;
	Button checkListButton;
	Button gridViewExample;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);

		shopProviderButton = getButtonById(R.id.shop_provider_test_butto);
		shopProviderButton.setOnClickListener(getShopButtonOnClickListener());

		textViewExampleButton = getButtonById(R.id.text_view_examples);
		textViewExampleButton
				.setOnClickListener(getTextViewExamplesButtonOnClickListener());

		butonExamplesButton = getButtonById(R.id.button_examples_button);
		butonExamplesButton
				.setOnClickListener(getButtonExamplesButtonOnClickListener());

		shopListButton = getButtonById(R.id.button_shop_list_example);
		shopListButton
				.setOnClickListener(getListViewExampleButtonOnClickListener());

		checkListButton = getButtonById(R.id.button_show_checklist_example);
		checkListButton
				.setOnClickListener(getCheckistViewExampleButtonOnClickListener());

		gridViewExample = getButtonById(R.id.button_grid_view_example);
		gridViewExample
				.setOnClickListener(getGridViewWithImageButtonOnClickListener());
	}

	private OnClickListener getGridViewWithImageButtonOnClickListener() {
		return new OnClickListener() {
			public void onClick(View v) {
				startActivityByClass(GridViewWithImageAdapterExample.class);
			}
		};
	}

	private OnClickListener getCheckistViewExampleButtonOnClickListener() {
		return new OnClickListener() {
			public void onClick(View v) {
				startActivityByClass(CheckedListViewExample.class);
			}
		};
	}

	private OnClickListener getListViewExampleButtonOnClickListener() {
		return new OnClickListener() {
			public void onClick(View v) {
				startActivityByClass(ListViewExample.class);
			}
		};
	}

	private OnClickListener getButtonExamplesButtonOnClickListener() {
		return new OnClickListener() {
			public void onClick(View v) {
				startActivityByClass(ButtonExample.class);
			}
		};
	}

	private OnClickListener getTextViewExamplesButtonOnClickListener() {
		return new OnClickListener() {
			public void onClick(View v) {
				startActivityByClass(TextExamples.class);
			}
		};
	}

	private OnClickListener getShopButtonOnClickListener() {
		return new OnClickListener() {
			public void onClick(View arg0) {
				startActivityByClass(ShopProviderActivity.class);
			}
		};
	}

	private Button getButtonById(int id) {
		return (Button) findViewById(id);
	}

	private void startActivityByClass(Class<?> clazz) {
		Intent intent = new Intent(getApplicationContext(), clazz);
		startActivity(intent);
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}
}
